package great.project.annotation;

import great.util.IdCardValidatorUtils;

import javax.validation.Constraint;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import javax.validation.Payload;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * <div  style="border:2px solid none;margin:20px;padding:15px;font-size:24px;text-align:center;color:aqua;">
 *
 *	身份证校验
 *
 *  </div>
 *
 * @author zhangshun
 * @date 2021/2/5 16:25
 */
@Documented
@Target({ElementType.PARAMETER, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = IdentityCardNumber.IdentityCardNumberValidator.class)
public @interface IdentityCardNumber {

	String message() default "身份证号码不合法";

	Class<?>[] groups() default {};

	Class<? extends Payload>[] payload() default {};


	/**
	 * 具体的判断逻辑
	 */
	class IdentityCardNumberValidator implements ConstraintValidator<IdentityCardNumber, String> {

		@Override
		public boolean isValid(String value, ConstraintValidatorContext context) {
			return IdCardValidatorUtils.isValidatedAllIdCard(value);
		}

	}

}